package com.cynen.crawler;


import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.InputStream;

public class CrawlerFirst {
    public static void main(String[] args) throws Exception {
        // 1.打开浏览器
        CloseableHttpClient httpClient = HttpClients.createDefault();
        // 2.输入网址
        HttpGet httpget = new HttpGet("http://www.baidu.com");
        //3.发起请求,
        CloseableHttpResponse httpResponse = httpClient.execute(httpget);
        //4.解析响应,获取数据
        if (httpResponse.getStatusLine().getStatusCode() == 200){
            // 获取成功...
            HttpEntity httpEntity = httpResponse.getEntity();
            String content = EntityUtils.toString(httpEntity,"utf8");
            System.out.println(content);
        }
    }
}
